package com.pyramid.main;

import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.pyramid.R;
import com.pyramid.api.LoginApi;

public class LoginActivity extends Activity {
	private EditText txtName;
	private EditText txtPassword;
    private Button loginButton;
    private String name;
    private String password;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.login);
		init();
	}
	private void init(){
		txtName=(EditText)findViewById(R.id.edit_login_email);
		name=txtName.getText().toString();
		txtPassword=(EditText)findViewById(R.id.edit_login_password);
		password=txtPassword.getText().toString();;
		loginButton=(Button)findViewById(R.id.but_login_sumit);
		loginButton.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				new LoginTask().execute(null);
			}
			
		});
	}
	
	private class LoginTask extends AsyncTask<Void, Void, Boolean> {

		public void onPreExecute() {
			super.onPreExecute();
		}

		public Boolean doInBackground(Void... params) {
			boolean temp = false;
			LoginApi api = new LoginApi();
			temp=api.login("susirgd", "abc123123");

			return temp;
		}

		public void onPostExecute(Boolean albums) {
			super.onPostExecute(albums);
            if(albums.booleanValue()){
            	Log.d("", "Login success");
            	finish();
            }
//			Log.d("", "searchResult ::: " + searchResult);
//			Intent  intent=new Intent(SearchActivity.this,
//					SearchResultActivity.class);
//			intent.putExtra("searchName", searchName);
//			intent.putExtra("searchResult", searchResult);
//			startActivity(intent);
			// for(int i=0;i<countryData.getCities().size();i++){
			// }

		}

	}
}
